﻿using Newtonsoft.Json;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace DAMS.Models
{
    /// <summary>
    /// 站点分类
    /// </summary>
    public class Category:BaseModel
    {
        /// <summary>
        /// 分类ID
        /// </summary>
        public int ID { get; set; }

        /// <summary>
        /// 分类名称
        /// </summary>
        [Required]
        [Display(Name="分类名称")]
        public string Name { get; set; }

        /// <summary>
        /// 父分类ID
        /// </summary>
        [Required]
        [Display(Name = "上级分类ID")]
        public int ParentID { get; set; }

        /// <summary>
        /// 左值
        /// </summary>
        [Required]
        [Display(Name = "左值")]
        public int LeftNum { get; set; }
        /// <summary>
        /// 右值
        /// </summary>
        [Display(Name = "右值")]
        public int RightNum { get; set; }
        /// <summary>
        /// 层级（顶层为0级）
        /// </summary>
        [Required]
        [Display(Name = "层级")]
        public int Layer { get; set; }

        /// <summary>
        /// 分类的类型
        /// </summary>
        [Required]
        [Display(Name = "分类类型")]
        public CategoryType Type { get; set; }
        /// <summary>
        /// 分类在显示在某个导航栏
        /// </summary>
        [Required]
        [Display(Name = "显示位置")]
        public int ShowType { get; set; }

        /// <summary>
        /// 内容
        /// </summary>
        [Display(Name = "内容")]
        public string Content { get; set; }
        /// <summary>
        /// HTML页面的描述
        /// </summary>
        [Display(Name = "HTML页面描述")]
        public string HtmlDescription { get; set; }
        /// <summary>
        /// Html页面关键字
        /// </summary>
        [Display(Name = "HTML页面关键字")]
        public string HtmlKeyWord { get; set; }

        /// <summary>
        /// 模版:
        /// 当Type类型为Home，Template储存首页模版页面文件名
        /// 当Type类型为Category，Template为列表页模版文件名
        /// 当Type类型为SinglePage，Template为单页模版文件名
        /// 当Type类型为Url，Template为链接Url。
        /// </summary>
        [Display(Name = "模版或Url")]
        public string Template { get; set; }
        /// <summary>
        /// 仅当Type为Category，ArticleTemplate为文章页模版
        /// </summary>
        [Display(Name = "内容页模版")]
        public string ArticleTemplate { get; set; }
        /// <summary>
        /// 父类导航属性
        /// </summary>
        [NotMapped]
        [JsonIgnore]
        public Category Parent { get; set; }
        /// <summary>
        /// 子类列表导航属性
        /// </summary>
        [NotMapped]
        [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
        public virtual List<Category> Children { get; set; }
        /// <summary>
        /// 构造函数：初始化子类列表
        /// </summary>
        public Category()
        {
            //Children = new List<Category>();
        }
    }

    public class CategoryCut
    {
        public CategoryCut()
        {
            Children = new List<CategoryCut>();
        }
        [JsonProperty("id")]
        public int ID { get; set; }
        [JsonProperty("name")]
        public string Name { get; set; }
        public int ParentID { get; set; }
        [JsonIgnore]
        public List<CategoryCut> Children { get; set; }
        [JsonProperty("open")]
        public bool Open
        {
            get { return Children.Count > 0; }
        }
        [JsonProperty(PropertyName = "children", NullValueHandling = NullValueHandling.Ignore)]
        
        public List<CategoryCut> Child
        {
            get { return Children.Count > 0 ? Children : null; }
        }



    }
}
